package com.solocredit.finance.utils.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.solocredit.finance.R
import com.solocredit.finance.app.MyApp
import com.solocredit.finance.base.utils.DensityUtils
import com.solocredit.finance.base.utils.ImageUtil
import com.solocredit.finance.databinding.DialogMullaBindCardDeleteBinding
import com.solocredit.finance.http.HttpHelper
import com.solocredit.finance.utils.event.MullaEventType
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/31 13:45
 * @Annotation：绑卡删除dialog
 */
class BindCardDeleteDialog: ProDialog {
    private lateinit var binding: DialogMullaBindCardDeleteBinding
    private var mCallback: IDialogCallback? = null

    //事件备注
    private var eventRemark = ""

    override fun initWindow() {
        val params = window?.attributes
        params?.width = MyApp.app.getPhoneWidth() - DensityUtils.dp2px(30f)
        params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.attributes = params
        window?.setWindowAnimations(R.style.picker_view_slide_anim) //修改动画样式
        window?.setGravity(Gravity.BOTTOM)
    }

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }


    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogMullaBindCardDeleteBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.imgClose) //关闭
        setOnClickListener(R.id.btnLeft)
        setOnClickListener(R.id.btnRight)
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        when(v?.id){
            R.id.imgClose,
            R.id.btnLeft -> {
                HttpHelper.addMullaEventAction(MullaEventType.CLICK.MULLA_CLICK_USER_ACCOUNT_DELETE_TIPS_CANCEL,eventRemark)
            }
            else -> {
                HttpHelper.addMullaEventAction(MullaEventType.CLICK.MULLA_CLICK_USER_ACCOUNT_DELETE_TIPS_CONFIRM,eventRemark)
            }
        }
        if(mCallback != null){
            mCallback?.onClick(v)
        }
    }

    /**
     * 设置需要删除的账户信息
     */
    @SuppressLint("SetTextI18n")
    fun setBindAccountInfo(info: JSONObject){
        ImageUtil.instance?.loadImageUrl(context,binding.accountLayout.imgLogo,info.optString("walletLogo"), R.mipmap.icon_holder)
        binding.accountLayout.textName.text = info.optString("walletDesc")
        binding.accountLayout.textNumber.text = "+" + info.optString("walletMobile")
        //不显示删除
        binding.accountLayout.imgDelete.visibility = View.GONE
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addMullaEventAction(MullaEventType.DIALOG.MULLA_DIALOG_USER_ACCOUNT_DELETE_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.addMullaEventAction(MullaEventType.DIALOG.MULLA_DIALOG_USER_ACCOUNT_DELETE_TIPS_DISMISS,eventRemark)
    }
}